<?php

/**
 * uniBoard Admin form inputs templates
 *
 * Light and fast forum solution for web 2.0-like communities.
 *
 * @package		uniBoard
 * @author		Rafał Pitoń
 * @license		http:// www.gnu.org/licenses/gpl-3.0.html
 * @since		Version 0.1
 * 
 * ------------------------------------------------------------------------
 * 
 * $Date: 2010-08-26 19:41:02 +0000 (Thu, 26 Aug 2010) $
 * $Revision: 48 $
 * $Author: rafio.xudb@gmail.com $
 */

// ------------------------------------------------------------------------

class tpl_form_inputs extends class_templates_abstract{
	
	/**
	 * Main class pointer
	 *
	 * @var object
	 */
	
	private $appCore	= NULL;

	/**
	 * Zebras list
	 *
	 * @var array
	 */
	
	public $zebras 		= array();
	
	// ------------------------------------------------------------------------

	/**
	 * Creates ACP display class
	 *
	 */
	
	function __construct( $appCore){
		
		// Store appCore pointer
		$this -> appCore = $appCore;
		
	}
	
	// ------------------------------------------------------------------------

	/**
	 * Button template
	 *
	 * @param array $tpl_vars
	 * @return string
	 */
	
	function tpl_button( $tpl_vars = array()){
	
		return '<input id="' . htmlspecialchars( $tpl_vars['field_name']) . '" name="' . htmlspecialchars( $tpl_vars['field_name']) . '" class="' . htmlspecialchars( $tpl_vars['field_class']) . '" type="submit" value="' . htmlspecialchars( $tpl_vars['field_title']) . '" />';
			
	}
	
	// ------------------------------------------------------------------------

	/**
	 * Text input
	 *
	 * @param array $tpl_vars
	 * @return string
	 */
	
	function tpl_text_input( $tpl_vars = array()){
	
		return '<input id="' . $tpl_vars['field_name'] . '" name="' . $tpl_vars['field_name'] . '" type="text" class="form_text" ' . ( $tpl_vars['field_width'] > 0 ? ' style="width: ' . ((integer) $tpl_vars['field_width']) . 'px" ' : '') . 'value="' . htmlspecialchars( $tpl_vars['field_value']) . '"/>';
			
	}
	
	// ------------------------------------------------------------------------

	/**
	 * Password input
	 *
	 * @param array $tpl_vars
	 * @return string
	 */
	
	function tpl_pass_input( $tpl_vars = array()){
	
		return '<input id="' . $tpl_vars['field_name'] . '" name="' . $tpl_vars['field_name'] . '" type="password" class="form_text" ' . ( $tpl_vars['field_width'] > 0 ? ' style="width: ' . ((integer) $tpl_vars['field_width']) . 'px" ' : '') . 'value="' . htmlspecialchars( $tpl_vars['field_value']) . '"/>';
		
	}
	
	// ------------------------------------------------------------------------

	/**
	 * Multiple choice list body
	 *
	 * @param array $tpl_vars
	 * @return string
	 */
	
	function tpl_multilist_body( $tpl_vars = array()){
	
		return '<div class="form_multi_list">
	' . $tpl_vars['multilist_items'] . '
</div>';
			
	}
	
	// ------------------------------------------------------------------------

	/**
	 * Multiple choice list item
	 *
	 * @param array $tpl_vars
	 * @return string
	 */
	
	function tpl_multilist_item( $tpl_vars = array()){
	
		// Generation id
		$generation_id = $this -> appCore -> n();
		
		// Update zebras
		$this -> updateZebras( 'multilist_item');
			
		return '<div class="form_multi_item_' . $this -> zebra( 'multilist_item', '0|1', '', ''). '">
		<input id="mlist_item_' . $generation_id . '" name="' . $tpl_vars['value_name'] . '[' . $tpl_vars['value_id'] . ']" type="checkbox" value="1" ' . ( $tpl_vars['item_checked'] == true ? 'checked="checked"' : '') . ' /> <label for="mlist_item_' . $generation_id . '">' . $tpl_vars['item_title'] . '</label>
	</div>';
			
	}
	
	// ------------------------------------------------------------------------

	/**
	 * Text area input
	 *
	 * @param array $tpl_vars
	 * @return string
	 */
	
	function tpl_text_area( $tpl_vars = array()){
	
		return '<textarea id="' . htmlspecialchars( $tpl_vars['field_name']) . '" name="' . htmlspecialchars( $tpl_vars['field_name']) . '" class="form_text_area">' . htmlspecialchars( $tpl_vars['field_value']) . '</textarea>';
			
	}
	
	// ------------------------------------------------------------------------

	/**
	 * Big Text area input
	 *
	 * @param array $tpl_vars
	 * @return string
	 */
	
	function tpl_big_text_area( $tpl_vars = array()){
	
		return '<textarea id="' . htmlspecialchars( $tpl_vars['field_name']) . '" name="' . htmlspecialchars( $tpl_vars['field_name']) . '" class="form_text_area_large">' . htmlspecialchars( $tpl_vars['field_value']) . '</textarea>';
			
	}
	
	// ------------------------------------------------------------------------

	/**
	 * Check-box input
	 *
	 * @param array $tpl_vars
	 * @return string
	 */
	
	function tpl_check_box( $tpl_vars = array()){
	
		return '<input name="' . ( key_exists( 'field_name', $tpl_vars) ? $tpl_vars['field_name'] : null). '" id="' . ( key_exists( 'field_name', $tpl_vars) ? $tpl_vars['field_name'] : null). '" class="form_checkbox' . (strlen( ( key_exists( 'field_class', $tpl_vars) ? $tpl_vars['field_class'] : null)) > 0 ? ' ' . $tpl_vars['field_class'] : ''). '" type="checkbox" value="1" ' . (( key_exists( 'field_select', $tpl_vars) ? $tpl_vars['field_select'] : null) == true ? 'checked="checked"' : ''). '/>';
			
	}
	
	// ------------------------------------------------------------------------

	/**
	 * File selection input
	 *
	 * @param array $tpl_vars
	 * @return string
	 */
	
	function tpl_file_upload( $tpl_vars = array()){
	
		return '<input name="' . $tpl_vars['field_name'] . '" id="' . $tpl_vars['field_name'] . '" type="file" class="form_text"/>';
			
	}
	
	// ------------------------------------------------------------------------

	/**
	 * Yes-No switch template
	 *
	 * @param array $tpl_vars
	 * @return string
	 */
	
	function tpl_yes_no( $tpl_vars = array()){
	
		return '<div class="form_yes_no">
							<div class="form_yes">
								<label for="' . htmlspecialchars( $tpl_vars['field_name']) . '_1">' . $this -> appCore -> lang['yes'] . '</label> <input id="' . htmlspecialchars( $tpl_vars['field_name']) . '_1" name="' . htmlspecialchars( $tpl_vars['field_name']) . '" type="radio" value="1" ' . ( $tpl_vars[ 'field_value'] ? 'checked' : '') . '/>
							</div>
							<div class="form_no">
								<input id="' . htmlspecialchars( $tpl_vars['field_name']) . '_0" name="' . htmlspecialchars( $tpl_vars['field_name']) . '" type="radio" value="0" ' . ( $tpl_vars[ 'field_value'] ? '' : 'checked') . '/> <label for="' . htmlspecialchars( $tpl_vars['field_name']) . '_0">' . $this -> appCore -> lang['no'] . '</label>
							</div>
						</div>';
			
	}
	
	// ------------------------------------------------------------------------

	/**
	 * Radio-button template
	 *
	 * @param array $tpl_vars
	 * @return string
	 */
	
	function tpl_radio( $tpl_vars = array()){
	
		return '<input id="' . ( empty( $tpl_vars['field_id']) ?  $tpl_vars['field_name'] : $tpl_vars['field_id']) . '" name="' . $tpl_vars['field_name'] . '" type="radio" value="' . $tpl_vars['field_value'] . '" ' . ( $tpl_vars['field_select'] == true ? 'checked' : '') . ' />';
			
	}
	
}